package logic

import (
	"api/model/mysql"
	"context"
	"srv/dev"
	"srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *dev.AddRequest) (*dev.AddResponse, error) {
	// todo: add your logic here and delete this line
	houses := mysql.Houses{
		Name:    in.Name,
		Address: in.Address,
		Typed:   in.Typed,
		Area:    int(in.Area),
		Floor:   int(in.Floor),
		Price:   float64(in.Price),
	}
	mysql.DB.Create(&houses)
	return &dev.AddResponse{
		Id: int64(houses.ID),
	}, nil
}
